/**
 * Copyright 2015 厦门市合趣息科技有限公司 (http://www.hequ.info). All rights reserved.
 * Encoding UTF-8
 * Version: 1.0
 * Date: 2015-4-9
 * History:	
 */

package com.kzc.web.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.kzc.domain.Admin;
import com.kzc.service.impl.BusinessServiceImpl;


/**
 *
 * @author 柯尊诚 (kezuncheng@hequ.info)
 * @version Revision: 1.0.0 Date: 2015-4-9
 */
public class LoginServlet extends HttpServlet{
    
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        
        BusinessServiceImpl service = new BusinessServiceImpl();
        Admin admin = service.login(username, password);
        if (admin!=null) {
            
            request.getSession().setAttribute("admin", admin);
            response.sendRedirect(request.getContextPath()+"/index.jsp");
            return;
        }
        System.out.println(admin);
        request.setAttribute("message", "用户名或密码错误！！！");
        request.getRequestDispatcher("").forward(request, response);
    }
    
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        
        doGet(request, response);
    }

}
